<?php

if (!defined('EXPONENT')) exit('');

$object = null;
if (isset($_POST['id'])) {
	$_POST['id'] = intval($_POST['id']);
	$object = $db->selectObject('present_songs','id='.intval($_POST['id']));
}

if (($object && exponent_permissions_check('edit',$loc)) || (!$object && exponent_permissions_check('create',$loc))) {
	$object = slide_item::update($_POST,$object);
	//$object->location_data = serialize($loc); // no location_data needed
	$song_id = 0;
	
	if (isset($object->id)) {
		$db->updateObject($object,'present_songs');
		$song_id = $object->id;
	} else {
		$song_id = $db->insertObject($object,'present_songs');
		if ($song_id == 0)
			validator::failAndReturnToForm('Song add failed.', $_POST);
	}
	if (!isset($_POST['goto_verse']))
		exponent_flow_redirect();
	else
	{
		// before redirect to edit_verse page, we must set song id into REQUEST
		$_REQUEST['id'] = $song_id;
		include("edit_verse.php");
	}
} else {
	echo SITE_404_HTML;
}

?>
